﻿package dt 
{	
	import dt.exchangeddata.StageInfo;
	import flash.events.DataEvent;
	import flash.events.Event;
	import flash.events.NetStatusEvent;
	import flash.events.SecurityErrorEvent;	
	import flash.net.Responder;
	import common.Utility;
	import game.ChannelControl;
	import game.SoundController;	
	import game.GameBase;
	import game.GlobalVariables;
	import game.events.EventData;	
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import game.constants.ConstData;
	import dt.exchangeddata.BetInfo;
	import flash.external.ExternalInterface;

	/**
	 * ...
	 * @author Nguyen Thi Bich Phuong (Daisy) 
	 * @author Doan Nguyen Thuy Nha Truc (Bamboo)
	 */
	public class DTGame extends GameBase {			
		public var gameInfo:StageInfo;
		private var channelControl:ChannelControl;
		public var snd:SoundController;		
		public var volumnGame:VolumeController;
		
		private static const BANKER:String = "1";
		private static const PLAYER:String = "2";
		private static const TIE:String = "3";
		private static const PPAIR:String = "1";
				
		public function DTGame() {	
			this.gameInfo = new StageInfo();
			this.snd = new SoundController();
			this.channelControl = new ChannelControl();
			GlobalVariables.gameRuleTxt = "ruleBacarat.txt";			
			// Run Flash	
			GlobalVariables.roomId = "2";
			this.channelControl.initFmsMonitor(GlobalVariables.fmsMonitor);
			this.channelControl.addEventListener(EventData.SET_FMS_CHANNEL, updateVideoHdl);
			super.stageInfo.userInfo.init(GlobalVariables.userName, GlobalVariables.preUser, GlobalVariables.isMain, GlobalVariables.roomId);
			this.connectToNc(GlobalVariables.rtmpStr, "0", GlobalVariables.userType, super.stageInfo.userInfo.preUser + super.stageInfo.userInfo.userName, GlobalVariables.pass, 
					GlobalVariables.pBetLtdSeq, GlobalVariables.sessionId, GlobalVariables.lang, GlobalVariables.versionNo, 
					GlobalVariables.forceReload, this.stageInfo.userInfo.isMain, GlobalVariables.siteName, GlobalVariables.casinoId, 
					GlobalVariables.ncName, GlobalVariables.ip, GlobalVariables.countryCode, GlobalVariables.loginTypeID, GlobalVariables.parentSID);			
			
			//End Run Flash		
			this.addEventListener(EventData.CONNECT_GAME, connectGame); 
			this.gameInfo.tableLiveBetPoolInfo.addEventListener(EventData.UPDATE_LIVEBETPOOL_GAME, updateLiveBetPoolGame);
			this.gameInfo.userLiveBetPoolInfo.addEventListener(EventData.UPDATE_LIVEBETPOOL_USER_PUBLIC, updateLiveBetPoolUserPublic);						
			
			super.stageInfo.userInfo.addEventListener(EventData.UPDATE_USERINFO, updateUserInfo);
			super.stageInfo.userInfo.addEventListener(EventData.UPDATE_CURRENCY, updateCurrency);
			super.stageInfo.userInfo.addEventListener(EventData.UPDATE_BALANCE, updateBalance);
			super.stageInfo.tableInfo.addEventListener(EventData.UPDATE_TABLEINFO, updateTableInfo);
			super.stageInfo.tableInfo.addEventListener(EventData.UPDATE_DATECLOCK, updateDateClock);
			super.stageInfo.welcomeMessage.addEventListener(EventData.UPDATE_WELCOME_MESSAGE, updateWelcomeMessage);
			//history
			this.gameInfo.historyInfo.addEventListener(EventData.UPDATE_HISTORY, updateGameHis);
			this.addEventListener(EventData.UPDATE_HISTORY, updateGameHis); //Daisy add showPoint
			
			//playerBankerPanel
			this.addEventListener(EventData.GET_ASK_PLAYER_BANKER_TYPE_1, askRoute);
			this.addEventListener(EventData.GET_ASK_PLAYER_BANKER_TYPE_2, askRoute);
			
			this.gameInfo.historyPlayerBankerInfo.addEventListener(EventData.INIT_ASK_PLAYER_BANKER_TYPE_1, updateAskRoute);
			this.gameInfo.historyPlayerBankerInfo.addEventListener(EventData.INIT_ASK_PLAYER_BANKER_TYPE_2, updateAskRoute);
			this.gameInfo.historyPlayerBankerInfo.addEventListener(EventData.UPDATE_ASK_ROUTE_1, updateAskRoute);
			this.gameInfo.historyPlayerBankerInfo.addEventListener(EventData.UPDATE_ASK_ROUTE_2, updateAskRoute);			
			
			this.addEventListener(EventData.CONFIRM_BETTING, confirmBettingHandler);	
			this.addEventListener(EventData.CLEAR_BETTING, clearBettingHandler);
			this.addEventListener(EventData.REBET_BETTING, rebetBettingHandler);
			
		    this.addEventListener(EventData.UPDATE_LIVEBETPOOL_USER_PUBLIC, updateLiveBetPoolUserPublic);
			this.addEventListener(EventData.UPDATE_LIVEBETPOOL_USER_PRIVATE, updateLiveBetPoolUserPrivate);
	
			this.addEventListener(EventData.GET_HISTORY, getHisRoombac);
			this.addEventListener(EventData.CHANGE_ROOM, getHisRoombac);
			
			this.addEventListener(EventData.BETPLACE_MOUSEOVER, hdlBetPlaceMouseOver);
			this.addEventListener(EventData.COUNTDOWN_COMPLETE, countDownCompleteHandler);
			this.addEventListener(EventData.GET_SOUND_COUNT_DOWN, hdlGetSoundCountDown);
			this.addEventListener(EventData.PLAY_VOD, playVodHdl);
			
			this.addEventListener(EventData.UPDATE_VIDEO, hdlUpdateFmsChannel);			
			this.addEventListener(EventData.UPDATE_SOUNDVOLUMEBACKGROUND, hdlUpdateSoundVolumnBackground);
			this.addEventListener(EventData.UPDATE_SOUNDBACKGROUND, hdlUpdateSoundBackground);
			this.addEventListener(EventData.STOP_LIST_SOUND, stopSoundHdl);
			this.addEventListener(EventData.LOCK_VOLUME_GAME, lockVolumeGameHdl);
			this.addEventListener(EventData.UN_LOCK_VOLUME_GAME, unlockVolumeGameHdl);
			
			this.addEventListener(EventData.GET_RECENT_BET, getRecentBetHdl); 
		}
		
		private function getRecentBetHdl(e:EventData):void {
			getRecentBet(uint(e.ms), 20);
		}
		
		private function unlockVolumeGameHdl(e:EventData):void {
			super.unClockVolumeGame();			
		}
		
		private function lockVolumeGameHdl(e:EventData):void {			
			super.lockVolumeGame();
		}
		
		private function stopSoundHdl(e:EventData):void {
			this.snd.stopSound();
		}
		
		private function hdlUpdateSoundVolumnBackground(e:EventData):void {
			var temp:Number = Number(e.newBalance);
			snd.setVolumnSound(temp);
			GlobalVariables.volumeSoundBackground = temp;			
		}
		
		private function hdlUpdateSoundBackground(e:EventData):void {		
			snd.playMusic(GlobalVariables.soundActive);			
		}
		
		private function hdlUpdateFmsChannel(e:EventData):void {
			this.channelControl.fmsChannel = e.ms;
			this.updateVideoPath(channelControl.fmsChannel);			
		}
		
		private function updateVideoHdl(e:EventData):void {			
			activeVideo(this.channelControl);			
		}
		
		public function activeVideo(channelControl:ChannelControl):void {
			this.channelControl = channelControl;
			super.currentView.initListChannel(this.channelControl.channelInfo.listChannel, this.channelControl.fmsChannel);
			this.updateVideoPath(channelControl.fmsChannel);
		}
		
		/**
		 * @author Bamboo
		 * @param	e
		 */
		private function hdlGetSoundCountDown(e:EventData):void 
		{
			super.sndCtr.playSound(GlobalVariables.dirSnd + "bip.mp3", GlobalVariables.volumeSounGame);
		}
		
		/**
		 * @author	Bamboo
		 * @param	e
		 * @usage 	call play VOD	 */
		private function playVodHdl(e:EventData):void 
		{
			var link:String = GlobalVariables.vodRtmp + "?fn=" + e.ms + ".flv";		
			ExternalInterface.call("popupVOD",link);
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function countDownCompleteHandler(e:Event):void {
			if(GlobalVariables.autoAcceptBetting == "1"){
				dobet();
			}
			this.currentView.initStopGame();			
		}
		
		/**
		 * @author Daisy
		 * @param	event
		 */
		private function hdlBetPlaceMouseOver(event:EventData):void {			
			var e:EventData = new EventData(EventData.BETPLACE_MOUSEOVER_SEND, true);
			e.chooseRoomBac = super.stageInfo.userInfo.roomId;
			dispatchEvent(e);			
		}
		
		/**
		 * @author Daisy
		 */
		public function rightClick():void {							
			this.currentView.rightBetting();
		}
		
		/**
		 * @author Daisy		 
		 * @param	chipName
		 */
		public function setChipActive(chipName:String) {
			this.currentView.setChipActive(chipName);
		}
		
		/**
		 * @author	@author	Bamboo
		 * @param	e
		 */
		private function getHisRoombac(e:EventData):void 	
		{			
			var room:String = e.activeRoomBac;
			if (e.type == EventData.GET_HISTORY)
			{
				super.ncId.call("getBetStatus", new Responder(super.successCallFMS, super.failCallFMS), room, super.stageInfo.userInfo.sessionId);
				super.currentView.lockAsk();
			}else if (e.type == EventData.CHANGE_ROOM)
			{
				//var flag:Boolean = false;				
				/*for (var i:int = 0; i < GlobalVariables.listGame.length; i++ )
				{
					if ((GlobalVariables.listGame[i].gameStatus == "free") && (GlobalVariables.listGame[i].tableId == room))
					{
						flag = true;
							break;
					}	
				}*/				
				/*flag = true;				
				event = new EventData(EventData.CHANGE_LOAD_GAME, true);
				event.activeRoomBac = room;
				dispatchEvent(event);
				
				if (flag)
				{
					super.currentView.unLockAsk();
					super.nc.close();
					super.ncId.close();
					GlobalVariables.roomId = room;
					super.stageInfo.userInfo.roomId = room;
					GlobalVariables.sessionId = "0";
					super.connectToNc(GlobalVariables.rtmpStr, "0", GlobalVariables.userType, super.stageInfo.userInfo.preUser + super.stageInfo.userInfo.userName, 
							GlobalVariables.pass, GlobalVariables.pBetLtdSeq, GlobalVariables.sessionId, 
							GlobalVariables.lang, GlobalVariables.versionNo, GlobalVariables.forceReload, 
							super.stageInfo.userInfo.isMain, GlobalVariables.siteName, GlobalVariables.casinoId, GlobalVariables.ncName,
							GlobalVariables.ip, GlobalVariables.countryCode, GlobalVariables.loginTypeID, GlobalVariables.parentSID);
				}else {
					var temp:String = GlobalVariables.langInfo.hashTable.lookupString("existTable");
					this.setTimelyMessage(temp);
					super.currentView.updatePosActiveRoom(super.stageInfo.userInfo.roomId);
				}
				*/
				var flag:int = -1; // -1: exist ; 0: change Table; 1: change Game
				flag = checkChangeRoom(room);
				if (flag == 0) {
					super.currentView.unLockAsk();
					super.nc.close();
					super.ncId.close();
					GlobalVariables.roomId = room;
					super.stageInfo.userInfo.roomId = room;
					GlobalVariables.sessionId = "0";
					super.connectToNc(GlobalVariables.rtmpStr, "0", GlobalVariables.userType, super.stageInfo.userInfo.preUser + super.stageInfo.userInfo.userName, 
							GlobalVariables.pass, GlobalVariables.pBetLtdSeq, GlobalVariables.sessionId, 
							GlobalVariables.lang, GlobalVariables.versionNo, GlobalVariables.forceReload, 
							super.stageInfo.userInfo.isMain, GlobalVariables.siteName, GlobalVariables.casinoId, GlobalVariables.ncName,
							GlobalVariables.ip, GlobalVariables.countryCode, GlobalVariables.loginTypeID, GlobalVariables.parentSID);
				}else if (flag == 1) {
					var event:EventData; 
					event = new EventData(EventData.CHANGE_LOAD_GAME, true);
					event.activeRoomBac = room;
					dispatchEvent(event);
				} else {
					var temp:String = GlobalVariables.langInfo.hashTable.lookupString("existTable");
					this.setTimelyMessage(temp);
					super.currentView.updatePosActiveRoom(super.stageInfo.userInfo.roomId);
				}							
			}			
		}
		/**
		 * @author Daisy
		 * @param	room
		 * @return
		 */
		private function checkChangeRoom(room:String):int {
			var flag:int = 0; // -1: exist ; 0: change Table; 1: change Game
			var activeBacName:String = "";
			for (var i:int = 0; i < GlobalVariables.arrListGameBacTable.length; i++) {
				if (room == GlobalVariables.arrListGameBacTable[i]) {
					activeBacName = GlobalVariables.arrListGameBacName[i];
					break;
				}
			}
			if (activeBacName.toUpperCase() != GlobalVariables.gameTableName.toUpperCase()) {
				flag = 1;
			}			
			return flag;			
		}
		
		/**
		 * @author	Bamboo
		 * @param	e
		 */	
		private function updateAskRoute(e:Event):void 
		{
			if(e.type == EventData.UPDATE_ASK_ROUTE_1)
				currentView.updateGameHisPlayerBanker(this.gameInfo.historyPlayerBankerInfo, ConstData.ASK_PLAYER_BANKER_TYPE_1, ConstData.ASK_TYPE_Y);
			else if(e.type == EventData.UPDATE_ASK_ROUTE_2)
				currentView.updateGameHisPlayerBanker(this.gameInfo.historyPlayerBankerInfo, ConstData.ASK_PLAYER_BANKER_TYPE_2, ConstData.ASK_TYPE_Y);
			else if(e.type == EventData.INIT_ASK_PLAYER_BANKER_TYPE_1)
				currentView.updateGameHisPlayerBanker(this.gameInfo.historyPlayerBankerInfo, ConstData.ASK_PLAYER_BANKER_TYPE_1, ConstData.ASK_TYPE_N);
			else if (e.type == EventData.INIT_ASK_PLAYER_BANKER_TYPE_2)
				currentView.updateGameHisPlayerBanker(this.gameInfo.historyPlayerBankerInfo, ConstData.ASK_PLAYER_BANKER_TYPE_2, ConstData.ASK_TYPE_N);
		}
		
		/**
		 * @author	Bamboo
		 * @param	e
		 */
		private function askRoute(e:Event):void 
		{
			if(e.type == EventData.GET_ASK_PLAYER_BANKER_TYPE_2)	
				getAskRoute(ConstData.ASK_PLAYER_BANKER_TYPE_2);	
			else if(e.type == EventData.GET_ASK_PLAYER_BANKER_TYPE_1)
				getAskRoute(ConstData.ASK_PLAYER_BANKER_TYPE_1);	
		}		
			
		/**
		 * @author Bamboo
		 * @param	e: event that reciever to update history
		 */
		private function updateGameHis(e:Event):void {				
			currentView.updateGameHis(this.gameInfo.historyInfo);				
		}			
		
		/**
		 * @author Bamboo
		 * @param	e: event that reviever from mainGame by menu
		 */
		override public function receiverInfoFromMainGame(nameObj:String):void {
			super.receiverInfoFromMainGame(nameObj);
		}
		
		/**
		 * @author Bamboo
		 * @param	info
		 */
		public override function updateGameStageInfo(info:String):void {			
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function connectGame(e:Event):void {
			super.connectToNcId(GlobalVariables.rtmpStr, super.stageInfo.userInfo.roomId, GlobalVariables.userType, 
								super.stageInfo.userInfo.preUser + super.stageInfo.userInfo.userName, 
								super.stageInfo.userInfo.sessionId, GlobalVariables.memberBetLtdSeq);		
				
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @param	tableNo
		 */
		override public function setBetStatus(result:String, tableNo:String):void {
			//Do load the first or change room
			if(!super.currentView.checkActiveRoom()){	
				super.setBetStatus(result, tableNo);
				super.currentView.updatePosActiveRoom(tableNo);
			}			
			if (Utility.checkResult(result)) {					
				this.gameInfo.tableLiveBetPoolInfo.returnSetBetStatus(result, tableNo);				
				this.gameInfo.historyInfo.setHistory(this.gameInfo.historyInfo.returnSetHistory(result), this.gameInfo.historyInfo.returnSetHistoryNum(result));				
				this.gameInfo.historyPlayerBankerInfo.setHistoryType_1(this.gameInfo.historyPlayerBankerInfo.returnSetHistoryType_1(result));
				this.gameInfo.historyPlayerBankerInfo.setHistoryType_2(this.gameInfo.historyPlayerBankerInfo.returnSetHistoryType_2(result));
			}			
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function updateUserInfo(e:Event):void {	 				
			super.setMinMaxTableInfo(super.stageInfo.userInfo.minBet, super.stageInfo.userInfo.maxBet);					
			// Update Chip Betting
			currentView.updateChipBetting(super.stageInfo.userInfo.minBet, super.stageInfo.userInfo.maxBet, 
										super.stageInfo.userInfo.balance, super.stageInfo.userInfo.chip);		
			currentView.updateTableMinMax(super.stageInfo.userInfo.minBet, super.stageInfo.userInfo.maxBet);
			currentView.updateUserName(super.stageInfo.userInfo.userName);
			// Call currUserBet to get the value betting of user
			callGetCurrUserBet();			
			/*MovieClip(parent.parent.parent).initUserInfo(GlobalVariables.userName);		*/			
		}				
		
		private function updateCurrency(e:Event):void {					
			/*MovieClip(parent.parent.parent).initCurrency(GlobalVariables.currency);		*/
			currentView.initCurrency(GlobalVariables.currency);
		}
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function updateBalance(e:Event):void {					
			currentView.updateBalance(super.stageInfo.userInfo.balance);
		}		
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function updateTableInfo(e:Event):void {				
			currentView.updateTableInfo(super.stageInfo.tableInfo);				
			if (super.stageInfo.tableInfo.status.toUpperCase() == "STOP") {				
				currentView.initStopGame();
			}				
		}		
		
		private function updateDateClock(e:EventData):void {
			super.currentView.updateDateClock(super.stageInfo.tableInfo);			
		}
		
	    /**
		 * @author Daisy
		 * @param	e
		 */
		private function updateWelcomeMessage(e:Event):void {			
			currentView.updateWelcomeMessage(super.stageInfo.welcomeMessage.strMsg);
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function updateLiveBetPoolGame(e:Event):void {		
			currentView.updateLiveBetPoolGame(this.gameInfo.tableLiveBetPoolInfo);
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function updateLiveBetPoolUserPublic(e:Event):void {			
			currentView.updateLiveBetPoolUserPublic(this.gameInfo.userLiveBetPoolInfo);
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function updateLiveBetPoolUserPrivate(e:Event):void {			
			currentView.updateLiveBetPoolUserPrivate();
		}
		
		/**
		 * @author Bamboo, Daisy
		 * @param	str
		 */
		override public  function confirmedConnection(str:String):void {	
    		super.confirmedConnection(str);		
	        //init interface
			super.currentView.initGame();
			//get data
			getCardResult();
			if (GlobalVariables.fmsChannel != "")
			{
				updateVideoPath(channelControl.fmsChannel);
			}
			super.ncId.call("getServerDate2", new  Responder(successCallFMS, failCallFMS), super.stageInfo.userInfo.sessionId);	
			
		}	
			
		
		/**
		 * @author Bamboo
		 * @param	sessionToken
		 */
		private function getCardResult():void{		
			super.ncId.call("getCardResult", new Responder(super.successCallFMS, super.failCallFMS), super.stageInfo.userInfo.sessionId);	
		}
		
		/**
		 * @author Bamboo
		 * @param	cardCode
		 * @param	where
		 * @param	instanceName
		 */
		override public function setCardResult(cardCode:String, where:String, instanceName:String) {
			currentView.updateGameCard(where, cardCode);
		}
		
		override public function setServerDate2(result:String):void {			
			super.setServerDate2(result);
			super.stageInfo.tableInfo.returnDateClock(result);
		}
		
		/**
		 * @author	Bamboo
		 * @param	type
		 */
		private function getAskRoute(type:String):void{
			super.ncId.call("askRoute", new Responder(super.successCallFMS, super.failCallFMS), super.stageInfo.userInfo.sessionId, type);
		}
		/**
		 * @author	Bamboo
		 * @param	result
		 * @usage	This function update history for BacHistoryPanel and playerBankerPanel
		 */
		override public function setAskRoute(result:String):void {
			if (Utility.checkResult(result)) {
					gameInfo.historyPlayerBankerInfo.setAskRouteType_1(gameInfo.historyPlayerBankerInfo.returnAskRouteType_1(result));
					gameInfo.historyPlayerBankerInfo.setAskRouteType_2(gameInfo.historyPlayerBankerInfo.returnAskRouteType_2(result));
					currentView.updateGameHisAsk(ConstData.ASK_TYPE_Y);
			}
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 */
		override public function currentBetPool(result:String):void {			
			if (Utility.checkResult(result)) {
				this.gameInfo.userLiveBetPoolInfo.returnCurrentBetPool(result);
			}
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @param	where
		 * @param	instanceName
		 * @usage This function is used call from FMS,
		 */	
		override public function setCardResultDelay(cardCode:String, where:String, instanceName:String):void {
			currentView.updateGameCard(where, cardCode);
		}
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is used call from FMS,
		 */
		override public function setPlaceBet(result:String):void {
			var ms:String;
			if (Utility.checkResult(result)) {			
				this.currentView.saveBettingSuccess();				
				
				//Show Bet Success
				this.currentView.showBetSuccess(true, true);
				
				ms = GlobalVariables.langInfo.hashTable.lookupString("BSuccess");
			} else {
				this.currentView.updateBetting();
				ms = GlobalVariables.langInfo.hashTable.lookupString(result.substr(1, result.length));
			}
			super.setTimelyMessage(ms);	
		}
		
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		override public function showGameResult(result:String):void 
		{
			
			super.showGameResult(result);
			if (Utility.checkResult(result)) {
				super.currentView.showWinLose(result);
				super.currentView.unLockAsk();
				playSoundBac(result);
			}
		}
		
		/**
		 * @author	Bamboo
		 * @param	result abc: a = 1 -> b = 1 ? (c = 1? BankerBPpair:BankerBpair):(c = 1? BankerPpair: banker)
		 * 						a = 2 -> b = 1 ? (c = 1? PlayerBPpair:PlayerBpair):(c = 1? PlayerPpair: player)
		 * 						a = 3 -> b = 1 ? (c = 1? TieBPpair:TieBpair):(c = 1? TiePpair: Tie)
		 */
		private function playSoundBac(result:String):void {
			// Banker win 
			if (result.substr(1, 1) == DTGame.BANKER) {
				if (result.substr(2, 1) == DTGame.PPAIR) {
					if (result.substr(3, 1) == DTGame.PPAIR) {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("BankerBPpair"), GlobalVariables.volumeSounGame);
					} else {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("BankerBpair"), GlobalVariables.volumeSounGame);
					}
				} else {
					if (result.substr(3, 1) == DTGame.PPAIR) {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("BankerPpair"), GlobalVariables.volumeSounGame);
					} else {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("banker"), GlobalVariables.volumeSounGame);
					}
				}
			} else if (result.substr(1, 1) == DTGame.PLAYER) {
				if (result.substr(2, 1) == DTGame.PPAIR) {
					if (result.substr(3, 1) == DTGame.PPAIR) {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("PlayerBPpair"), GlobalVariables.volumeSounGame);
					} else {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("PlayerBpair"), GlobalVariables.volumeSounGame);
					}
				} else {
					if (result.substr(3, 1) == DTGame.PPAIR) {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("PlayerPpair"), GlobalVariables.volumeSounGame);
					} else {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("player"), GlobalVariables.volumeSounGame);
					}
				}
			} else if (result.substr(1, 1) == DTGame.TIE) {
				if (result.substr(2, 1) == DTGame.PPAIR) {
					if (result.substr(3, 1) == DTGame.PPAIR) {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("TieBPpair"), GlobalVariables.volumeSounGame);
					} else {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("TieBpair"), GlobalVariables.volumeSounGame);
					}
				} else {
					if (result.substr(3, 1) == DTGame.PPAIR) {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("TiePpair"), GlobalVariables.volumeSounGame);
					} else {
						super.sndCtr.playSound(GlobalVariables.dirSnd + super.stageInfo.soundInfo.hashTable.lookupString("Tie"), GlobalVariables.volumeSounGame);
					}
				}
			}
		}
		
		
		/**
		 * @author	Bamboo
		 * @param	result
		 * @param	tableNo
		 */
		override public function showResult(result:String, tableNo:String):void 
		{	super.showResult(result, tableNo);
			if (Utility.checkResult(result)) {	
				if (this.gameInfo.historyInfo.odlResult == result)
					return;				
				this.gameInfo.historyInfo.setHistory(this.gameInfo.historyInfo.returnSetHistory(result), this.gameInfo.historyInfo.returnSetHistoryNum(result));		
				this.gameInfo.historyPlayerBankerInfo.setHistoryType_1(this.gameInfo.historyPlayerBankerInfo.returnSetHistoryType_1(result));
				this.gameInfo.historyPlayerBankerInfo.setHistoryType_2(this.gameInfo.historyPlayerBankerInfo.returnSetHistoryType_2(result));
			}
		}

		/**
		 * @author Daisy
		 * @param	e
		 */
		private function confirmBettingHandler(e:EventData):void {		
			dobet();
		}
		
		/**
		 * @author Daisy
		 */
		private function dobet():void {
			var confirmBetting:String = this.currentView.confirmBetting();			
			var arrBetting:Array = new Array();
			if (confirmBetting != "") {				
				arrBetting = confirmBetting.split("@");					
				super.ncId.call("placeBet_DT", new Responder(super.successCallFMS, super.failCallFMS), super.stageInfo.userInfo.sessionId, GlobalVariables.memberBetLtdSeq,
				super.stageInfo.tableInfo.gameSet, super.stageInfo.tableInfo.gameNo, arrBetting[0], arrBetting[1]);
			}
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function clearBettingHandler(e:EventData):void {			
			this.currentView.clearBetting(e);			
		}
		
		/**
		 * @author Daisy
		 * @param	e
		 */
		private function rebetBettingHandler(e:EventData):void {
			this.currentView.rebetBetting(e);
		}		
		
		/**
		 * @author Daisy
		 * @param	result
		 * @usage This function is called from FMS, return result CurrUserBet
		 */
		override public function setPlaceBet1(result:String):void {				
			if(Utility.checkResult(result)){
				var currBetInfo:BetInfo = new BetInfo();
				var pos:int = 1;
				var len:int = 9;
				for (var i:int = 0; i < currBetInfo.arrBettingCode.length; i++) {
					if(parseInt(result.substr(pos, len)) != 0) 
					currBetInfo.arrBettingValue[i] = parseInt(result.substr(pos, len));			
					pos += len;
				}
				this.currentView.updateCurrUserBet(currBetInfo);
			}
		}
		
		/**
		 * @author	Bamboo
		 * @param	result
		 */
		override public function setVODId(result:String):void 
		{
			super.setVODId(result);
			if (Utility.checkResult(result)) {
				this.gameInfo.historyInfo.returnVodId(result);
			}
		}
		
		override public function updateVideoPath(fmsVideo:String):void {
			super.updateVideoPath(fmsVideo);
		}
		/**
		 * @author Bamboo
		 * @param	fmsVideo
		 */
		/*public function updateVideoPath(fmsVideo:String) {
			var temp:String = fmsVideo + "/" + super.stageInfo.userInfo.roomId + "/" + super.stageInfo.userInfo.roomId +  "_2";			
			super.currentView.updateVideoPath(temp);			
		}*/
		/*public function updateVideoPath(fmsVideo:String) {
			var temp:String;
			switch(super.stageInfo.userInfo.roomId) {
				case "1":
				case "4":
				case "7":
				case "12":
				case "13":
				case "14":
				case "15":
				case "16":
					temp = GlobalVariables.fmsChannel + "/" + super.stageInfo.userInfo.roomId + "@" + super.stageInfo.userInfo.roomId +  "_1";
					break;	
				case "20":
					temp = GlobalVariables.fmsChannel + "@" + "grd-t03-live1";
					break;
				case "21":
					temp = GlobalVariables.fmsChannel + "@" + "gmg-t01-live2_2";
					break;	
				case "22":
					temp = GlobalVariables.fmsChannel + "@" + "gmg-l01-live2_2";
					break;
				case "23":
					temp = GlobalVariables.fmsChannel + "@" +  "gmg-t02-live2_2";
					break;
				case "24":
					temp = GlobalVariables.fmsChannel + "@" +  "grd-t04-live1_2";
					break;
				case "25":
					temp = GlobalVariables.fmsChannel + "@" + "grd-f01-live1";
					break;
				case "26":
					temp = GlobalVariables.fmsChannel + "@" +  "gmg-f01-live2";
					break;	
				case "27":
					temp = GlobalVariables.fmsChannel + "@" +  "grd-l01-live2";
					break;
				case "28":
					temp = GlobalVariables.fmsChannel + "@" +  "grd-s01-live1";
					break;
				case "29":
					temp = GlobalVariables.fmsChannel + "@" +  "bav-r01-live1";
					break;
			}
			GlobalVariables.fmsChannel = temp;
			trace("GlobalVariables.fmsChannel:" + GlobalVariables.fmsChannel + "temp:" + temp + "super.stageInfo.userInfo.roomId" + super.stageInfo.userInfo.roomId);
			super.currentView.updateVideoPath(GlobalVariables.fmsChannel);					
		}*/
	    /**
		 * @author Daisy
		 * @usage Close Connecttion
		 */
		override public function closeConnect():void {
			this.nc.close();
			this.ncId.close();
			this.currentView.stopVideo();
		}
		
		/**
		 * @author Bamboo
		 * @param	result
		 */
		/*
		 override public function setClosedTables(result:String):void {			
			var temp:Array = result.split("*");
			temp.shift();
			super.currentView.updateTablesClose(temp);
		}*/
		
		/**
		 * @author Bamboo
		 * @param	InstanceName
		 * @param	gameType
		 * @param	eventType
		 */
		override public function sendStatusGame(InstanceName:String, gameType:String, eventType:String):void {		   
		    if (eventType == "NewGameset" && InstanceName == super.stageInfo.userInfo.roomId){				
				this.gameInfo.historyInfo.setHistory(this.gameInfo.historyInfo.returnSetHistory("0"), this.gameInfo.historyInfo.returnSetHistoryNum("0")); 
				this.gameInfo.historyPlayerBankerInfo.setHistoryType_1(this.gameInfo.historyPlayerBankerInfo.returnSetHistoryType_1("0"));
				this.gameInfo.historyPlayerBankerInfo.setHistoryType_2(this.gameInfo.historyPlayerBankerInfo.returnSetHistoryType_2("0"));
		    }
		}
		
	}
}